package filter;

//import java.util.logging.Filter;
//import java.util.logging.LogRecord;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebFilter("/*")
public class AllFilter implements Filter {


    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        servletRequest.setCharacterEncoding("utf-8");
        servletResponse.setCharacterEncoding("utf-8");
        HttpServletResponse re = (HttpServletResponse) servletResponse;
        re.setHeader("Access-Control-Allow-Origin", "http://127.0.0.1:8848");
        re.setHeader("Access-Control-Allow-Credentials", "true");
        re.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT");
        re.setHeader("Access-Control-Max-Age", "3628800");
        re.setHeader("Access-Control-Allow-Headers", "x-requested-with,Authorization,content-type");
        filterChain.doFilter(servletRequest, re);

    }

    @Override
    public void destroy() {

    }
}
